part of _;

extension on CartPage {
  Widget view_item(CartMainModel item_carts) {
    return Card(
      margin: EdgeInsets.fromLTRB(10, 10, 10, 0),
      color: Colors.white,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(10),
        child: Slidable(
          key: Key(item_carts.sku),
          endActionPane: ActionPane(
            extentRatio: 100 / yScreenSize().width,
            motion: ScrollMotion(),
            children: [
              SlidableAction(
                padding: EdgeInsets.zero,
                backgroundColor: Colors.red,
                foregroundColor: Colors.white,
                icon: Icons.delete,
                label: '删除',
                onPressed: (context) {
                  yPost(IFinal.Jkids.removeCart, {
                    "sku": item_carts.sku,
                  }, (isSuccess, results, code, message) {
                    if (isSuccess) {
                      model_carts!.items_carts.removeWhere((element) => element.sku == item_carts.sku);
                      model_carts!.count_carts = model_carts!.items_carts.length;
                      setState(() {});
                      yBroadcast_send(IFinal.Broadcasts.refreshProductDetail, params: {
                        "count_carts": model_carts!.count_carts,
                      });
                      yToast("删除成功");
                    }
                  });
                },
              ),
            ],
          ),
          child: YButton(
            height: 120,
            padding: EdgeInsets.all(10),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                YButton(
                  width: 25,
                  height: 25,
                  borderRadius: BorderRadius.circular(25),
                  enable: item_carts.countLeft > 0,
                  child: item_carts.countLeft > 0 ? (item_carts.isSelect ? Icon(Icons.check_circle, color: YConfig.themeColor) : Icon(Icons.circle_outlined, color: Colors.grey)) : Icon(Icons.remove_circle_rounded, color: Colors.grey, size: 25),
                  onTap: () {
                    setState(() {
                      item_carts.isSelect = !item_carts.isSelect;
                    });
                  },
                ),
                YSpacer(width: 10),
                YImageCorner(100, 100, item_carts.img, 10),
                YSpacer(width: 10),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(item_carts.titleProduct.fixAutoLines(), overflow: TextOverflow.ellipsis, maxLines: 1),
                      YSpacer(height: 8),
                      Container(
                        padding: EdgeInsets.fromLTRB(5, 2, 5, 2),
                        decoration: BoxDecoration(color: Colors.grey.shade100, borderRadius: BorderRadius.circular(2)),
                        child: Text(item_carts.titleType.fixAutoLines(), maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle(color: Colors.grey)),
                      ),
                      YExpanded(),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Text("￥", style: TextStyle(color: YConfig.themeColor, fontSize: 12, fontWeight: FontWeight.bold)),
                          Text(item_carts.money.toString(), style: TextStyle(color: YConfig.themeColor, fontSize: 18, fontWeight: FontWeight.bold)),
                          YExpanded(),
                          !item_carts.isSelect
                              ? (item_carts.countLeft <= 0 ? Text("库存不足", style: TextStyle(color: Colors.grey)) : YEmpty())
                              : MyNumPicker(
                                  value: item_carts.count_input,
                                  max: item_carts.countLeft,
                                  onChange: (value) => setState(() => item_carts.count_input = value),
                                ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
            onTap: () {
              AppUtils.goIntent(this, Enum_IntentType.GoProductDetail, params: {
                "id": item_carts.spu,
              });
            },
          ),
        ),
      ),
    );
  }

  Widget view_bottom() {
    return Container(
      padding: EdgeInsets.fromLTRB(10, 5, 10, 5),
      color: Colors.white,
      child: Row(
        children: [
          YButton(
            width: 80,
            child: Row(
              children: [
                getIsAllSelect() ? Icon(Icons.check_circle_rounded, color: YConfig.themeColor) : Icon(Icons.circle_outlined, color: Colors.grey),
                YSpacer(width: 5),
                Text("全选"),
              ],
            ),
            onTap: () {
              var has = false;
              model_carts?.items_carts.forEach((item_carts) {
                if (item_carts.isSelect) has = true;
              });
              model_carts?.items_carts.forEach((item_carts) {
                if (item_carts.countLeft > 0) item_carts.isSelect = !has;
              });
              setState(() {});
            },
          ),
          YExpanded(),
          YAnimatedSwitcher(
            child: getSelectModels().isEmpty
                ? YEmpty()
                : Row(
                    children: [
                      Text("已选${getSelectModels().length}件,"),
                      Text("合计:"),
                      Text("￥", style: TextStyle(color: YConfig.themeColor)),
                      Text(getSelectTotalMoney().toYuan(isFen: false), style: TextStyle(color: YConfig.themeColor, fontSize: 18, fontWeight: FontWeight.bold)),
                      YSpacer(width: 10),
                      YButton(
                        width: 100,
                        height: 40,
                        borderRadius: BorderRadius.circular(99),
                        decoration: BoxDecoration(gradient: IFinal.Colors.btnThemeGradient),
                        child: Text("去结算", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
                        onTap: () {
                          Navigator.pop(context);
                          yIntent(OrderConfirmPage(getSelectModels()));
                        },
                      ),
                    ],
                  ),
          ),
        ],
      ),
    );
  }
}
